//
// Created by liushuai on 18-8-5.
// 环形队列实现
#include <iostream>
#ifndef EX8_ARRAY_QUEUE_HPP
#define EX8_ARRAY_QUEUE_HPP
template <typename T,int size = 100>
class array_queue {
private:
    int first,last;
    T storage[size];
public:
    array_queue();
    void enqueue(T);
    T dequeue();
    bool isFull();
    bool isEmpty();

};
template <typename T,int size>
void array_queue<T,size>::enqueue(T item) {
    if(!isFull())
        if(last == size-1||last == -1)
        {
            storage[0] = item;
            last = 0;
            if(first == -1)
                first = 0;
        } else
            storage[++last] == item;
    else std::cout<<"Full queue.\n";
}
template <typename T,int size>
T array_queue<T,size>::dequeue() {
    T  tmp;
    tmp = storage[first];
    if(first == last)
        last = first = -1;
    else if(first == size-1)
        first = 0;
    else
        first++;
    return tmp;
}
template <typename T,int size>
bool array_queue<T,size>::isEmpty() {
    return first == -1;
}
template <typename T,int size>
bool array_queue<T,size>::isFull() {
    return first == 0&&last == size-1||first == last+1;
}
template <typename T,int size>
array_queue<T,size>::array_queue():first(-1),last(-1) {}

#endif //EX8_ARRAY_QUEUE_HPP
